package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.Admin;
import org.apache.ibatis.annotations.*;

/**
 * @program: hrph
 * @InterfaceName AdminMapper
 * @description:管理员Mapper
 * @author: WY
 **/
@Mapper
public interface AdminMapper {
    //新增
    @Insert("insert into hrp_admin values (null,#{account},#{password})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void insert(Admin admin);

    //删除(物理)
    @Delete("delete from hrp_admin where id=#{id}")
    void delete(int id);

    //登录(查询)
    @Select("select *from hrp_admin where account=#{account}")
    @Results(
            {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "account",property = "account"),
                    @Result(column = "password",property = "password"),
                    @Result(column = "id",property = "perms",many = @Many(select = "com.woniuxy.hrp.mapper.PermMapper.getById"))
            }
    )
    Admin getByAccount(String account);

    @Select("select * from hrp_admin where account=#{account} and password=#{password}")
    Admin getByAccountAndPassword(@Param("password")String password,@Param("account")String account);
}
